package com.t4.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.t4.model.process.ProcessTemplate;
import com.t4.model.process.ProcessType;
import com.t4.process.mapper.ProcessTemplateMapper;
import com.t4.process.mapper.ProcessTypeMapper;
import com.t4.process.service.ProcessTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProcessTypeServiceImpl extends ServiceImpl<ProcessTypeMapper, ProcessType> implements ProcessTypeService {

    @Resource
    private ProcessTemplateMapper processTemplateMapper;

    @Override
    public List<ProcessType> findProcessType() {
        List<ProcessType> processTypeList = baseMapper.selectList(null);

        for(ProcessType processType: processTypeList){
            LambdaQueryWrapper<ProcessTemplate> queryWrapper = new LambdaQueryWrapper();
            queryWrapper.eq(ProcessTemplate::getProcessTypeId, processType.getId())
                            .eq(ProcessTemplate::getStatus, 1);

            List<ProcessTemplate> processTemplates = processTemplateMapper.selectList(queryWrapper);
            processType.setProcessTemplateList(processTemplates);
        }

        return processTypeList;
    }
}
